package info.wodongde.proxy.servlet;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.ServletInputStream;
import javax.servlet.http.*;

public class ProxyServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {/*
		response.setContentType("text/plain");
		response.getWriter().println("Hello, world");*/
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		request.setCharacterEncoding("UTF-8");
		ServletInputStream in = request.getInputStream();
		StringBuilder builder = new StringBuilder();
		
		while (true) {
			int c = in.read();
			if (c <= 0) {
				break;
			}
			
			builder.append((char) c);
		}
		in.close();
		
		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");
		response.getWriter().println(new String(builder.toString().getBytes(), "UTF-8"));
	}

}
